package cn.aylog.parse;

import cn.aylog.anno.Fruite;
import cn.aylog.anno.MyAnno;
import cn.aylog.pojo.Apple;

import java.lang.reflect.Field;

public class AnnoParser {

    public static void getInfo(Class<?> clazz) {

        if(clazz.isAnnotationPresent(MyAnno.class)) {
            MyAnno myAnno = clazz.getAnnotation(MyAnno.class);
            System.out.println(myAnno.value());
        }

        // 获取定义的变量
        Field[] fields = clazz.getDeclaredFields();
        for(Field field : fields) {
            // 判断是否拥有指定的注解
            if(field.isAnnotationPresent(Fruite.class)) {
                // 获取指定注解
                Fruite fruite = field.getAnnotation(Fruite.class);
                System.out.println(fruite.value());
            }
        }
    }

    public static void main(String[] args) {
        getInfo(Apple.class);
    }
}
